package cn.qidisoft.edu.hzjt.service.zyc.impl;

import cn.qidisoft.core.common.code.QdfRespCode;
import cn.qidisoft.core.common.exception.dao.DBException;
import cn.qidisoft.core.common.log.LoggerAdapter;
import cn.qidisoft.core.common.log.LoggerAdapterFactory;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.edu.hzjt.dao.zyc.DybMapper;
import cn.qidisoft.edu.hzjt.dao.zyc.DzbMapper;
import cn.qidisoft.edu.hzjt.model.zyc.PartyBranch;
import cn.qidisoft.edu.hzjt.model.zyc.PartyCommitteeMember;
import cn.qidisoft.edu.hzjt.model.zyc.PartyLeagueMember;
import cn.qidisoft.edu.hzjt.service.zyc.IDzbService;
import cn.qidisoft.edu.hzjt.utils.LogType;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/***
 * 党支部servie实现类
 * 
 * @author 0
 *
 */
@Service
public class DzbServiceImpl implements IDzbService {

	@Autowired
	private DybMapper dybMapper; 
	
	@Autowired
	private DzbMapper dzbMapper;

	protected static final LoggerAdapter LOGGER = LoggerAdapterFactory.getLogger(LogType.HZJT_LOGGER.val);

	@Override
	public PaginationBean<PartyBranch> getListData(Map<String, Object> queryMap, Page page) {
		int c = dzbMapper.getCounnt(queryMap);
		int totalRecords = 0;
		totalRecords = (int) c;
		PaginationBean<PartyBranch> pageHolder = new PaginationBean<PartyBranch>(page, totalRecords);
		List<PartyBranch> resultList = dzbMapper.getListData(queryMap,
				new RowBounds((pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(), pageHolder.getPageSize()));
		pageHolder.setPageList(resultList);
		return pageHolder;
	}

	@Override
	public int addDzbinfo(PartyBranch partyBranch) {
		
		return dzbMapper.addDzbinfo(partyBranch);
	}

	@Override
	public PartyBranch getDzbmc(String dZBMC) {
		return dzbMapper.getDzbmc(dZBMC);
	}

	@Override
	public int insertwyb(List<PartyCommitteeMember> list) {
		
		return dzbMapper.insertwyb(list);
	}
	
	@Override
    @Transactional
    public void delete(List<Integer> data) {
        try {
        	dzbMapper.delete(data);
        } catch (Exception e) {
            LOGGER.error("delete [{}] error," + this.getClass().getName() + "=[{}]",
                this.getClass().getName(),
                ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
            throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(),
                e);
        }
    }

	@Override
	public PartyCommitteeMember getSjInfo(String dZBSJXM) {
		return dzbMapper.getSjInfo(dZBSJXM);
	}

	@Override
	public PartyCommitteeMember getWyInfo(Integer valueOf) {
		
		return dzbMapper.getWyInfo(valueOf);
	}

	@Override
	public void insertDyb(List<PartyLeagueMember> pList) {
		
		 for(PartyLeagueMember pMember : pList) {
			 dybMapper.insertDyb(pMember);			 
		 }
		
	}

	@Override
	public List<PartyLeagueMember> seleteDyb(Integer empName) {
		return dybMapper.seleteDyb(empName);
	}

	@Override
	public List<PartyLeagueMember> seletePcmByParentId(Integer string) {
		return dzbMapper.seletePcmByParentId(string);
	}

	@Override
	public List<PartyBranch> getDzbList(PartyBranch partyBranch) {
		return dzbMapper.getDzbList(partyBranch);
	}

	@Override
	public PartyBranch getDzbById(Integer id) {
		return dzbMapper.getDzbById(id);
	}
    
	public List<PartyCommitteeMember> getWylist(Integer id) {
		return dzbMapper.getWylist(id);
	}

	@Override
	public void deleteWy(Integer getdZBSJID) {
		dzbMapper.deleteWy(getdZBSJID);
		
	}

	@Override
	public void updateDzbinfo(PartyBranch partyBranch) {
		dzbMapper.updateDzbinfo(partyBranch);
		
	}

	@Override
	public List<PartyBranch> getAllDzbinfo(PartyBranch partyBranch) {
		return dzbMapper.getAllDzbinfo(partyBranch);
	}

	@Override
	public PartyBranch selectDzb(PartyBranch pBranch) {
		return dzbMapper.selectDzb(pBranch);
	}
	
}
